package com.ruoyi.controller.admin.app;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.app.AppSettingDB;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.admin.AdminAppSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/admin/app/commonSetting")
@Slf4j
public class AppCommonSetting {

    @Resource
    private AdminAppSettingService adminAppSettingService;

//    @PreAuthorize("@ss.hasPermi('app:app:set')")
    // http://localhost/dev-api/admin/app/commonSetting/activityDesc
    @Log(title = "后台-记账", businessType = BusinessType.EXPORT)
    @PostMapping("/{name}")
    public void commonSetting(@PathVariable("name") String name ,@RequestBody String value) {
        // 将name改为 蛇形写法
        String snake = StrUtil.toUnderlineCase(name);
        adminAppSettingService.updateAppSetting(snake, value);
        log.info("name:{}, value:{}", name, value);
    }

    @GetMapping("getSetting")
    public AjaxResult getSetting(){
        AppSettingDB item = adminAppSettingService.findSetting();
        // 转为对象
//        https://cloud-test.yunxiangfarm.cn/upload/2025/11/13/3265bd0e2f954912b1812fc41eae5ec6.jpg
        return AjaxResult.success(item);
    }

    // 保存富文本


}
